import { defineStore } from 'pinia';
import { GetUserinfo } from '@/api/login';

export const useAccount = defineStore('account', {
  state: () => ({
    userinfo: null,
    permissionList: [],
  }),
  actions: {
    // 清除用户信息
    clearUserinfo() {
      this.userinfo = null;
    },
    // 获取用户信息
    async getUserinfo() {
      // const { code, data } = await GetUserinfo();
      // if (+code === 200) {
      //   this.userinfo = data;
      //   return Promise.resolve(data);
      // }
      const data = {
        id: 1,
        name: 'zhangsan',
        role: 'admin',
        avatar: 'http://dummyimage.com/48x48/fb0a2a',
      };
      this.userinfo = data;
      return Promise.resolve(data);
    },
  },
});
